var formatTime = function(t) {
    var e = t.getFullYear(), r = t.getMonth() + 1, o = t.getDate(), m = t.getHours(), a = t.getMinutes(), n = t.getSeconds();
    return [ e, r, o ].map(formatNumber).join("/") + " " + [ m, a, n ].map(formatNumber).join(":");
}, formatNumber = function(t) {
    return (t = t.toString())[1] ? t : "0" + t;
};

/**
 * @function 调用易宝支付插件时，参数解析函数
 */
const getUrlParams = (prePayTn) => {
    const params = {};
    const paramStr = prePayTn.split('?')[1];
    if (!paramStr) {
      return params;
    }
    const paramArr = paramStr.split('&');
    paramArr.forEach(param => {
      const [key, value] = param.split('=');
      params[key] = decodeURIComponent(value);
    });
    return params;
}

/**
 * @function 显示toast弹框
 * @param {*} msg 弹框提示信息
 * @param {*} time 弹框消失时间
 */
const showToast = (msg, time) => {
    wx.showToast({
        title: msg,
        icon: 'none',
        duration: time || 2000
    })
}

module.exports = {
    formatTime,
    getUrlParams,
    showToast
};